package com.asiainfo.dacp.resource.model;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.asiainfo.dacp.resource.util.VMInfoUtil;
import com.asiainfo.dacp.resource.vo.BrokerResource;

@Component
public class ResourceModel {
	
	public BrokerResource getResourceModel(String brokerId,String brokerIp,String diskName){
		VMInfoUtil vMInfo = VMInfoUtil.getVmInfo();
		Map<String, Long> phyOSStatus=vMInfo.getPhyOSStatus();
		BrokerResource brokerResource = new BrokerResource();
		brokerResource.setBrokerId(brokerId);
		brokerResource.setBrokerIp(brokerIp);
		brokerResource.setFreeMemory(phyOSStatus.get("freePhysicalMemory"));
		brokerResource.setTotalMemory(phyOSStatus.get("totalPhysicalMemory"));
		try {
			Long[] netIo= vMInfo.net(brokerIp);
			brokerResource.setNetRecv(netIo[0]);
			brokerResource.setNetSent(netIo[1]);
			Long[] diskIoInfo = vMInfo.getDiskIoInfo(diskName);
			brokerResource.setIoRead(diskIoInfo[0]);
			brokerResource.setIowrite(diskIoInfo[1]);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return brokerResource;
	}
	

}
